Skip to content

[#80] Add priceForNextMint + tokenBond ABI and 24h price change utility#82

Merged
realproject7 merged 2 commits intomainfrom
task/80-bond-abi-price-utils
Mar 15, 2026
Merged

[#80] Add priceForNextMint + tokenBond ABI and 24h price change utility#82
realproject7 merged 2 commits intomainfrom
task/80-bond-abi-price-utils

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

  • Added priceForNextMint and tokenBond MCV2_Bond view functions to lib/contracts/abi.ts
  • Added get24hPriceChange(tokenAddress) utility — pure on-chain reads using block number diff (~43200 blocks ≈ 24h on Base at 2s)
  • Added getTokenTVL(tokenAddress) utility reading tokenBond().reserveBalance
  • Updated existing getTokenPrice() to use priceForNextMint (simpler single-call vs getReserveForToken with 1e18 amount)

Test plan

  • npm run lint passes
  • npm run typecheck passes
  • Verify getTokenPrice() returns correct price via priceForNextMint
  • Verify get24hPriceChange() returns percentage change for a known token
  • Verify getTokenTVL() returns reserve balance and reserve token address

Fixes #80

🤖 Generated with Claude Code

- Add priceForNextMint and tokenBond view functions to lib/contracts/abi.ts
- Add get24hPriceChange() using block number diff (~43200 blocks on Base)
- Add getTokenTVL() reading tokenBond().reserveBalance
- Update getTokenPrice() to use priceForNextMint (simpler single-call)

Fixes #80

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES

Summary

The PR covers the ABI additions and price helpers from #80, but the new TVL utility hardcodes 18 decimals even though tokenBond() returns the reserve token address separately. That makes the formatted TVL incorrect whenever the reserve token is not 18-decimal.

Findings

  • [medium] getTokenTVL() formats reserveBalance with a fixed 18-decimal scale instead of using the reserve token's actual decimals or returning only the raw value. Because this helper is explicitly reading reserveToken from tokenBond(), callers can reasonably expect the formatted TVL to match that token's units. If a storyline bond ever uses a 6-decimal reserve such as USDC, this will overstate TVL by 1e12.
    • File: lib/price.ts:231
    • Suggestion: either fetch decimals() for reserveToken before formatting, or drop the formatted tvl field and return only tvlRaw plus reserveToken so formatting happens at the call site with the correct scale.

Decision

Requesting changes because the helper bakes in an unsafe unit assumption that can surface incorrect balances in the UI.

Instead of hardcoding 18 decimals, read the reserve token's actual
decimals via ERC-20 decimals() call for correct TVL formatting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Summary

The follow-up addresses the blocking unit-handling issue in getTokenTVL() by reading the reserve token's decimals on-chain before formatting. The PR now matches the acceptance criteria for #80.

Findings

  • No blocking findings.

Decision

Approving because the ABI additions, price utility updates, and TVL formatting are now consistent with the issue requirements.

@realproject7 realproject7 merged commit 98afd21 into main Mar 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P5-R3] Add priceForNextMint + tokenBond ABI + 24h price change utility

2 participants